<template>
	<view class="content">
		<image class="banner" src="../../static/index-banner.jpg" mode="widthFix"></image>
		<view class="top-bar">
			<view class="top-item" @click="house">
				<image src="../../static/house.png" class="icon fix"></image>
				<text class="name">房源信息</text>
			</view>
			<view class="top-item" @click="reservation">
				<image src="../../static/yuyue.png" class="icon fix"></image>
				<text class="name">预约看房</text>
			</view>
			<view class="top-item" @click="lease">
				<image src="../../static/lease.png" class="icon fix"></image>
				<text class="name">我的租赁</text>
			</view>
		</view>
		<u-notice-bar :text="noticeList" :step="true" duration="2000" fontSize="16" color="#fff"
			bgColor="#409EFF"></u-notice-bar>
		<view class="list">
			<text class="list-title">热门房源</text>
			<view class="list-box">
				<view class="list-item" v-for="item in list" :key="item.id" @click="goDetails(item)">
					<image :src="item.houseImg" mode="widthFix"></image>
					<text class="name">{{item.name}}</text>
					<view class="tips-box">
						<text class="tips">{{item.houseType}}</text>
						<text class="price">{{item.price}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noticeList: [],
				list: []
			}
		},
		onLoad() {
			this.getHousingResourcesInfoList()
			this.getNoticeList()
		},
		methods: {
			//获取房源数据
			async getHousingResourcesInfoList() {
				const res = await this.$api.getHousingResourcesInfoList({
					pageIndex: -1,
					pageSize: -1,
					state: 0
				})
				// console.log(res)
				this.list = res.records.slice(0, 10)
			},
			//获取公告数据
			async getNoticeList() {
				const res = await this.$api.getNoticeList({
					pageIndex: -1,
					pageSize: -1,
				})
				// console.log(res)
				res.records.forEach((el) => {
					this.noticeList.push(el.content)
				})
			},
			house() {
				uni.navigateTo({
					url: '/pages/house/house'
				})
			},
			reservation() {
				uni.navigateTo({
					url: '/pages/house/house?page=' + 'yuyue'
				})
			},
			lease() {
				uni.navigateTo({
					url: '/pages/lease/lease'
				})
			},
			goDetails(item) {
				uni.navigateTo({
					url: '/pages/details/details?data=' + JSON.stringify(item)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 88vh;
		background-color: #f4f4f5;
		padding-bottom: 80rpx;

		.banner {
			width: 100%;
		}

		.top-bar {
			display: flex;
			justify-content: space-around;
			padding: 40rpx 0;
			background-color: #fff;

			.top-item {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.icon {
					width: 128rpx;
					height: 128rpx;
					margin-bottom: 20rpx;
				}

				.name {
					color: #409EFF;
					font-size: 50rpx;
				}
			}
		}

		.list {
			display: flex;
			flex-direction: column;
			margin-top: 40rpx;
			padding: 0 40rpx;

			.list-title {
				font-size: 36rpx;
				font-weight: bold;
			}

			.list-box {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.list-item {
					width: 320rpx;
					display: flex;
					flex-direction: column;
					border-radius: 20rpx;
					margin-top: 40rpx;
					overflow: hidden;
					box-shadow: 2px 2px 10px 2px rgba(0, 0, 0, .2);

					image {
						width: 100%;
					}

					.name {
						font-size: 32rpx;
						padding: 20rpx;
					}

					.tips-box {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 0 10rpx;
						margin-bottom: 20rpx;

						.tips {
							font-size: 28rpx;
							padding: 4rpx 8rpx;
							font-size: 28rpx;
							color: #849aae;
							background-color: rgba(132, 154, 174, .1);
							border-radius: 4rpx;
						}

						.price {
							font-size: 28rpx;
							color: red;
						}
					}
				}
			}
		}
	}
</style>